﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Transactions {
    import Engine.Transactions.*;
    import Events.*;
    import Classes.*;
    import Display.*;
    import Display.NeighborUI.*;
    import Modules.stats.experiments.*;

    public class TInitialVisit extends Transaction {

        private var m_recipientId:String;
        private var m_senderId:String;

        public function TInitialVisit(_arg1:String, _arg2:String){
            this.m_senderId = _arg1;
            this.m_recipientId = _arg2;
        }
        public function get recipientId():String{
            return (this.m_recipientId);
        }
        public function get senderId():String{
            return (this.m_senderId);
        }
        override public function perform():void{
            var _local1:Object = {
                recipientId:this.m_recipientId,
                senderId:this.m_senderId
            };
            signedCall("VisitorService.initialVisit", "neighborVisit", _local1);
        }
        protected function showTutorial(_arg1:GenericPopupEvent):void{
            var _local2:Player = Global.player.findFriendById(Global.getVisiting());
            if (_local2 != null){
                Global.guide.notify("FirstVisit");
            };
        }
        override protected function onComplete(_arg1:Object):void{
            var _local3:Object;
            var _local4:int;
            var _local5:Boolean;
            var _local6:Object;
            var _local7:Number;
            var _local8:Number;
            var _local9:Number;
            var _local10:Boolean;
            var _local11:int;
            var _local12:Dialog;
            Global.player.dailyVisits++;
            Global.player.visitorEnergy = _arg1["energyLeft"];
            var _local2:Player = Global.player.findFriendById(Global.getVisiting());
            if (_arg1.hasOwnProperty("reward")){
                _local3 = _arg1["reward"];
                _local4 = _local3["status"];
                _local5 = (_local4 == 1);
                if (_local3.hasOwnProperty("rewards")){
                    _local6 = _local3["rewards"];
                    _local7 = ((_local6["coins"]) || (0));
                    _local8 = ((_local6["energy"]) || (0));
                    _local9 = ((_local6["xp"]) || (0));
                    Global.player.gold = (Global.player.gold + _local7);
                    Global.player.xp = (Global.player.xp + _local9);
                    Global.player.updateEnergy(_local8, new Array("energy", "earnings", "neighbor_visit_first", ""));
                    _local10 = (((((_local7 > 0)) || ((_local8 > 0)))) || ((_local9 > 0)));
                    if (((_local2) && (_local10))){
                        _local11 = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_FTV_WITH_MARKENTING);
                        if (_local11 == ExperimentDefinitions.FTV_MARKETING){
                            _local12 = new FriendFTVRewardDialog(_local2, _local7, _local8, _local9, (_local5) ? this.showTutorial : null);
                        } else {
                            _local12 = new FriendEnterRewardDialog(_local2, _local7, _local8, _local9, (_local5) ? this.showTutorial : null);
                        };
                        UI.displayPopup(_local12);
                    };
                };
            };
        }

    }
}//package Transactions 
